package com.aua.book.android.xml;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.util.DisplayMetrics;
import android.widget.ImageView;

public class ProgressDisplay {

  public static void displayProgress(AndroidBookActivity app, int progress) {

    DisplayMetrics displaymetrics = new DisplayMetrics();
    app.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int displaysWidth = displaymetrics.widthPixels;
    int numOfDots = displaysWidth / 80;
    int numOfBigDots = progress * numOfDots / 100;

    ImageView image = (ImageView) app.findViewById(R.id.progress_dots);

    ImageView i = new ImageView(app);
    i.setImageResource(R.drawable.progress_dots);
    BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
    Bitmap bitmap = drawable.getBitmap();

    int START_X = bitmap.getWidth() / 2 - 30 - numOfBigDots * 87;
  
    System.out.println(" bitmap.getWidth()=" +  bitmap.getWidth());
    int START_Y = 0;
    int WIDTH_PX = displaysWidth;
    int HEIGHT_PX = bitmap.getHeight();
    // Crop bitmap
    Bitmap newBitmap = Bitmap.createBitmap(bitmap, START_X, START_Y, WIDTH_PX, HEIGHT_PX, null, true);
    // Assign new bitmap to ImageView
    image.setImageBitmap(newBitmap);
    image.setVisibility(ImageView.VISIBLE);

  }

}
